﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.ComponentModel;

namespace ProjectNocturnalFool
{
    class PartyInfoControl : UserControl
    {
        protected SpriteFont font;
        public int displayChar = Constants.INDEX_INVALID;

        LabelControl Name, Class, Race, Health, Mana; 


        /// <summary>
        /// Loads Content of Info
        /// </summary>
        public override void LoadContent()
        {
            base.LoadContent();

            _bgTexture = TacticsGame.Instance.Content.Load<Texture2D>(Constants.TextureButtonRegular);
            font = TacticsGame.Instance.gameFont;

            depth = ControlDepth.NonDrag;

            Name = UILoader.addMessageLabel(x + Constants.ControlSmallOffsets, y + Constants.TextOffset, "Name: ");
            Class = UILoader.addMessageLabel(x + Constants.ControlSmallOffsets, y + (Constants.TextOffset * 2), "Class: ");
            Race = UILoader.addMessageLabel(x + Constants.ControlSmallOffsets, y + (Constants.TextOffset * 3), "Race: ");
            Health = UILoader.addMessageLabel(x + Constants.ControlSmallOffsets, y + (Constants.TextOffset * 4), "Health: ");
            Mana = UILoader.addMessageLabel(x + Constants.ControlSmallOffsets, y + (Constants.TextOffset * 5), "Mana: ");

            controls.Add(Name);
            controls.Add(Class);
            controls.Add(Race);
            controls.Add(Health);
            controls.Add(Mana);
        }

        /// <summary>
        /// Displays Character info
        /// </summary>
        public override void Update(GameTime gameTime)
        {
            base.LoadContent();

            _bgTexture = TacticsGame.Instance.Content.Load<Texture2D>(Constants.TextureButtonRegular);
            font = TacticsGame.Instance.gameFont;

            depth = ControlDepth.NonDrag;

            if (displayChar != Constants.INDEX_INVALID)
            {
                Name.message = "Name: " + GameLogic.Instance.gameCharacterSession.charList[displayChar].name;
                Race.message = "Race: " + GameLogic.Instance.gameCharacterSession.charList[displayChar].charRace.Description();
                Class.message = "Class: " + GameLogic.Instance.gameCharacterSession.charList[displayChar].charClass.Description();
                Health.message = "Health: " + GameLogic.Instance.gameCharacterSession.charList[displayChar].health.ToString();
                Mana.message = "Mana: " + GameLogic.Instance.gameCharacterSession.charList[displayChar].mana.ToString();
            }
            else
            {
                Name.message = "";
                Race.message = "";
                Class.message = "";
                Health.message = "";
                Mana.message = "";
            }
        }

        /// <summary>
        /// Draws the control
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Draw(GameTime gameTime)
        {
            TacticsGame.Instance.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);
            Rectangle targetRect = new Rectangle(x, y, width, height);

            TacticsGame.Instance.spriteBatch.Draw(_bgTexture,
                                                  targetRect,
                                                  null,
                                                  Color.White,
                                                  0,
                                                  Vector2.Zero,
                                                  SpriteEffects.None,
                                                  0);

            TacticsGame.Instance.spriteBatch.End();

            if (displayChar != Constants.INDEX_INVALID)
            {
                base.Draw(gameTime);
            }
        }

    }
}
